//
// Created by haoy on 2017/6/20.
//

#ifndef RTC_XSWITCH2_RTP_RED_HPP
#define RTC_XSWITCH2_RTP_RED_HPP

#include <cstdint>
#include <list>

#include "rtp/rtp_map.hpp"

/// as per https://tools.ietf.org/html/rfc2198
///
///      0                   1                    2                   3
///      0 1 2 3 4 5 6 7 8 9 0 1 2 3  4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
///      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///      |F|   block PT  |  timestamp offset         |   block length    |
///      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
///

class RtpRed {
public:
    class Block {
    public:
        int codec;
        uint8_t* payload;
        uint32_t payload_size;
        uint16_t ts_offset;
    };
public:
    Block primary_block;
    std::list<Block> redundant_blocks;

    int read(const uint8_t* data, int size, const RtpMap* rtp_map);
    int write(uint8_t* data, int size, const RtpMap* rtp_map) const;
};


#endif //RTC_XSWITCH2_RTP_RED_HPP
